package com.xpsoft.oa.service.admin.impl;


import java.text.DecimalFormat;

import org.apache.commons.lang.StringUtils;

import com.xpsoft.core.service.impl.BaseServiceImpl;
import com.xpsoft.core.util.DateUtil;
import com.xpsoft.oa.dao.admin.AdminContractDao;
import com.xpsoft.oa.model.admin.AdminContract;
import com.xpsoft.oa.service.admin.AdminContractService;

public class AdminContractServiceImpl extends BaseServiceImpl<AdminContract> implements AdminContractService{
	private AdminContractDao dao;
	
	public AdminContractServiceImpl(AdminContractDao dao) {
		super(dao);
		this.dao=dao;
	}

	@Override
	public String getNewContractNo() {
		// TODO Auto-generated method stub
		String firstCode = "X";
		String nowYear = DateUtil.shortYear();
		String search = firstCode+nowYear;
		String newNo="";
		String contractNo = dao.getMaxNo(search);
		if(StringUtils.isBlank(contractNo)){
			newNo = search+ "001z";
		}else{
			DecimalFormat df = new DecimalFormat("000");
			newNo = search + df.format(1 + Integer.parseInt(contractNo.substring(3,contractNo.length()-1)))+"z";
		}
		return newNo;
	}

}